import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'styleCommon.dart';

class TopInfo extends StatelessWidget {
  final String tips; //顶部提示
  final String loadGoodsAddr; //第一行文案
  final String unloadGoodsAddr; //第二行文案
  Function callBack; //点击导航回调
  TopInfo(this.tips, this.loadGoodsAddr, this.unloadGoodsAddr, this.callBack);
  @override
  Widget build(BuildContext context) {
    print('this');
    return getChatTemplate();
  }

  Widget getChatTemplate() {
    return Container(
      decoration: BoxDecoration(
        image: DecorationImage(
            image: AssetImage("images/left.png"),
            alignment: Alignment(-0.99, 0.5),
            scale: 1.8),
      ),
      child: Column(
        children: [returnTip(), returnAddress()],
      ),
    );
  }

  //卡片内容上部分提示
  Widget returnTip() {
    return Container(
      padding: EdgeInsets.only(bottom: 3),
      margin: EdgeInsets.only(bottom: 18),
      height: 25,
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(12.0),
        gradient: LinearGradient(
            begin: FractionalOffset.topLeft,
            end: FractionalOffset.bottomRight,
            colors: [
              Color(0xFFFFECD8),
              Color(0x00FFECD8),
            ],
            stops: [
              0.42,
              1.0
            ]),
      ),
      child: Row(
        children: [
          ClipRRect(
            //四个圆角的角度
            borderRadius: BorderRadius.circular(25),
            //被裁剪的子Widget
            child: Container(
              //渐变样式的背景装饰
              decoration: BoxDecoration(
                gradient: LinearGradient(
                    begin: FractionalOffset.topRight,
                    end: FractionalOffset.topLeft,
                    colors: [
                      Color(0x1AFF3A31),
                      Color(0xFFFF372F),
                    ],
                    stops: [
                      0.14,
                      1.0
                    ]),
              ),
              //圆角背景大小
              height: 25,
              width: 25,
              //中间的小图标
              child: Icon(
                //图标数据
                Icons.priority_high,
                //图标大小
                size: 14,
                //图标的颜色
                color: Colors.white,
              ),
            ),
          ),
          Padding(
            padding: EdgeInsets.only(left: 7),
            child: Text(
              tips,
              style: fontStyle2,
            ),
          )
        ],
      ),
    );
  }

//展示起始地址信息
  Widget returnAddress() {
    return Column(
      children: [
        returnAddressRow(loadGoodsAddr, Color(0xFF00ABFF)),
        SizedBox(height: 12),
        returnAddressRow(unloadGoodsAddr, mainColor)
      ],
    );
  }

  Widget returnAddressRow(String address, Color color) {
    return Row(
      children: [
        Container(
          margin: EdgeInsets.only(right: 8),
          width: 7,
          height: 7,
          decoration: BoxDecoration(
            shape: BoxShape.circle,
            color: color,
          ),
        ),
        Text(address,
            style: TextStyle(fontSize: 16.0, color: Color(0xFF414B67))),
        SizedBox(width: 8),
        FlatButton(
          minWidth: 18,
          child: Image(
            image: AssetImage("images/navigation.png"),
            width: 16,
            height: 16,
          ),
          onPressed: () {
            // 按钮点击回调
            callBack(loadGoodsAddr);
          },
        ),
      ],
    );
  }
}
